/* 
 * EK.require (ek.require.js)
 * Inspired by jQuery Require plugin (Jose I. Paris)
 * 
 * JS Enrichment Kit 0.1.0 (http://enrichyourjs.com)
 * Copyright (c) 2008 Pink Hominid
 * Licensed under terms of the MIT License (ek.license.txt)
 * 
 * IE 6.0+, FF 1.5+ Tested
 * 
 * TODO: 
 * 
 * Remove dependency on jQuery
 */

(function ($){
    $.extend({
        require: function (plugin, o) {
            o = $.extend({
                jsbase: null,
                cssbase: null,
                onload: null
            }, o || {});
      
            //EK.debug("js: " + $("script[@src*='" + plugin + ".js']").length);
            if (o.jsbase) {
                if ($("script[@src*='" + plugin + ".js']").length === 0) {
                    var s = document.createElement('script');
                    s.charset = 'utf-8';
                    s.type = 'text/javascript';
                    s.src = o.jsbase + '/' + plugin + '.js';
                    $('body')[0].appendChild(s);
                    $.getScript(s.src, o.onload);
                } else if(o.onload) {
                    o.onload();
                }
            }

            //EK.debug("css: " + $("link[@href*='" + plugin + ".css']").length);
            if(o.cssbase && $("link[@href*='" + plugin + ".css']").length === 0) {
                var l = document.createElement('link');
                l.charset = 'utf-8';
                l.type = 'text/css';
                l.rel = 'stylesheet';
                l.media = 'screen,print,projection';
                l.href = o.cssbase + '/' + plugin + '.css';
                $('head')[0].appendChild(l);
            }
        }
    });
})(jQuery);